package com.codedancer.campus.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.codedancer.campus.common.core.BaseMapper;
import com.codedancer.campus.po.Category;
import com.codedancer.campus.qo.category.CategoryPageSearchQo;
import org.apache.ibatis.annotations.Param;

public interface CategoryMapper extends BaseMapper<Category> {

    /**
     * 分页查询分类
     *
     * @param platePage
     * @param categoryPageSearchQo
     * @return
     */
    IPage<Category> page2Manager(Page<Category> platePage,
        @Param("categoryPageSearchQo") CategoryPageSearchQo categoryPageSearchQo);

    /**
     * 判断该板块下是否存在分类
     *
     * @param plateUuid
     * @param name
     * @return
     */
    default boolean existsByPlateUuid(String plateUuid, String name) {
        LambdaQueryWrapper<Category> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Category::getPlateUuid, plateUuid);
        lambdaQueryWrapper.eq(Category::getName, name);
        return selectCount(lambdaQueryWrapper) > 0;
    }
}
